<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="utf-8"/>
    <title>layui</title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" href="/lib/layui-v2.5.4/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all"/>
    <link rel="stylesheet" href="/css/public.css" media="all"/>
    <style>
        html, body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            background-color: #cbddf3;
        }

        .layui-code-ol {
            min-height: 680px;
        }

        .layui-form-item {
        !important;
            margin-bottom: 0px;
            border: 2px solid #99bce8;
            padding: 10px !important;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main" style="background-color: #cbddf3;">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">选择日期</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input dateSelect" name="startDate" id="startDate"
                               placeholder="yyyy-MM-dd">
                    </div>
                    <button class="layui-btn" type="button" id="logBtn"><i class="layui-icon layui-icon-log"></i>查看日志
                    </button>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">执行命令</label>
                    <div class="layui-input-inline">
                        <input type="text" name="patientId" id="patientId" placeholder="输入要执行的命令,例:ls"
                               class="layui-input" value="">
                    </div>
                    <button class="layui-btn layui-btn-danger" type="button" id="data-search-btn"><i
                            class="layui-icon layui-icon-component"></i>执行
                    </button>
                </div>
            </div>
        </form>
        <div class="layui-row layui-col-space6">
            <div class="showMessage layui-col-md12">
                <pre class="layui-code"></pre>
            </div>
        </div>
    </div>
</div>

<script src="/lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>

<script>
    layui.use(['form', 'table', 'layer', 'laydate', 'code'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            layer = layui.layer;

        var myDate = new Date();
        laydate.render({
            elem: '#startDate'
            , theme: '#393D49',
            calendar: true,
            value: myDate
        });

        layui.code({
            title: "结果",
            height: "6800px",
            about: false,
            skin: 'notepad'
        });

        $('#patientId').on('keydown', function (event) {
            if (event.keyCode == 13) {
                load($('#patientId').val());
                return false;
            }
        });


        $('#logBtn').on('click', function () {
            let date = $('#startDate').val();
            console.info(date);
            let commad = 'cat log/jbase_' + date + '.log';
            queryText(commad);
        })

        // 监听搜索操作
        $('#data-search-btn').on('click', function (data) {
            load($('#patientId').val());
        });

        function load(patientId) {
            if (patientId != '') {
                //执行搜索重载
                queryText(patientId);
            } else {
                layer.msg('命令不能为空！');
                $('#patientId').onfocus;
            }
            return false;
        }

        function queryText(command) {
            var index = layer.msg('拼命加载中...', {
                icon: 16
                , shade: 0.01,
                time: 0
            });
            $.ajax({
                url: "/sys/excuteLinux",
                type: "GET",
                data: {
                    command: command
                },
                success: function (obj) {
                    layer.close(index);
                    $(".showMessage").html('<pre class="layui-code">' + obj.data + '</pre>');
                    layui.code({
                        title: "结果",
                        height: "680px",
                        about: false,
                        skin: 'notepad'
                    });
                }
            });
        }

    });
</script>

</body>
</html>
